<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>二手主页</title>

		<meta name="viewport" content="initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!-- 引入css文件 -->
		<link rel="stylesheet" href="../css/sm.min.css">
		<link rel="stylesheet" href="../css/sm-extend.min.css">
		<link rel="stylesheet" href="../css/iconfont.css">
		<style type="text/css">
			#index {
				margin-top: 0.4rem;
			}
			.infinite-scroll-preloader {
				margin-top: -20px;
			}
			/* 卡片内容加边距 */
			.my-cont{
				padding:.2rem .99rem;
				text-align:center
				
			}
			/* 背景色白色 */
			.page, .page-group{
				background-color: white;
			}
			/* 去掉卡片边距 */
			.card{
				/* margin: 0; */
			}
			/* 用户字体 */
			.list-block .my-user{
				font-size :0.6rem;
				color:rgb(150,150,150);
			}
			/* 头像圆角 */
			.my-photo img{
				border-radius: 1rem;
			}
			/*商品*/
			.commodity-title{
				font-weight: bold;
				font-size: medium;
			}
			.commodity-price{
				font-weight: bold;
				color: red;
				padding-right: 5rem;
			}
			/* 用户 */
			.user-name{
				font-size :0.6rem;
				color:gray;
			}
			/* 跳转连接颜色 */
			a{
				color: inherit;
			}
			a:active{
				color: inherit;
			}
			
			/* 卡片主内容左右边距 */
			.my-data{
				padding-right: 7rem;
			}
		</style>
	</head>
	<body>
		<!-- page 容器 -->
		<div class="page" id="app">
			<!-- 标题栏 -->
			<header class="bar bar-nav" style="background-color: yellow;">
				<!-- 回首页 -->
				<a class="button button-link pull-left" href="../main-index.html">
					<span class="icon iconfont icon-home_light"></span>
					返回
				</a>
				<h1 class="title" style="color: #000000;">跳蚤市场</h1>
				<!-- 去搜索 -->
				<a class="button button-fill pull-right" href="market-search.html">
					<span class="icon icon-search"></span>
				</a>
			</header>
			
			<!-- 工具栏 -->
			<nav class="bar bar-tab" style="background-color: yellow;">
				<a class="tab-item external active" href="#">
					<span class="icon iconfont icon-chengshi"></span>
					<span class="tab-label">首页</span>
				</a>
				<a class="tab-item external" href="market-postgoods.html">
					<span class="icon iconfont icon-chuangzuo"></span>
					<span class="tab-label">发布商品</span>
				</a>
				<a class="tab-item external" href="market-message.html">
					<span class="icon iconfont icon-message"></span>
					<span class="tab-label">消息</span>
				</a>
				<a class="tab-item external" href="market-mymainpage.html">
					<span class="icon iconfont icon-peoplelist"></span>
					<span class="tab-label">我的</span>
				</a>
			</nav>

			<!-- 页面内容 -->
			<div class="content">
				<!-- 主内容 -->
				<div class="list-block">
					<a href="#" @click="goCommodity(commodity.id)" v-for="commodity in commodities">	
						<div class="card list-container">
							<div class="my-cont">
								<span>
									<img :src="imgSrc(commodity.picture)" width="260">
									<br/>
								</span>
								<span class="commodity-title">
									{{commodity.title}}<br/>
								</span>
								<span class="commodity-price">
									￥{{commodity.price}}
								</span>
								<span class="user-picture">
									<img :src="imgSrc(commodity.user.photo)" width="20">
								</span>
								<span class="user-name">{{commodity.user.nickname}}</span>
							</div>
						</div>
					</a>
				</div>
			</div>
		</div>
		<script src='../js/jquery-3.2.1.min.js'></script>
		<script src='../js/sm.js'></script>
		<script src='../js/sm-extend.js'></script>
		<script src='../js/vue.js'></script>
		<script src='../js/axios.min.js'></script>
		<script src="../js/config.js"></script>
		
		<script>
			//VUE
			var app = new Vue({
				el:"#app",
				data:{
					commodities:[]
				},
				created() {
					//初始加载所有商品
					this.initcommodities();
				},
				// 方法
				methods:{
					initcommodities: function() {
						axios.get(serviceIP+"/market/initcommodities",{
						 headers:{"token":token,"refreshtoken":refreshtoken}
						}).then(result => {
							this.commodities = result.data.data;
						});
					},
					
					//跳转商品页面
					goCommodity:function(id){
						window.location="market-commodity.html?commodityid="+id
					},
					//图片映射
					imgSrc: function(src) {
						return src;
					},
				},
			});
		</script>
		
		<script>
			$.init();
		</script>
	</body>

</html>
